/*
 * LagrangeInterpolator.h
 *
 *  Created on: 24 Aug 2011
 *      Author: Allan
 */

#ifndef LAGRANGEINTERPOLATOR_H_
#define LAGRANGEINTERPOLATOR_H_

// C++ includes
#include <vector>
using namespace std;

class LagrangeInterpolator
{
public:
	LagrangeInterpolator();
	
	LagrangeInterpolator(const vector<double>& xi, const vector<double>& yi, unsigned order = 1);
	
	const double 
	operator()(double x) const;
	
private:
	/// The interpolation points on the x-axis
	vector<double> xi;
	
	/// The interpolation points on the y-axis
	vector<double> yi;
	
	/// The order of the interpolation
	unsigned order;
	
private:
	void
	FindPosition(double x, unsigned& pos, unsigned& npoints) const;
	
	const double 
	LagrangeInterpolation(double x, const double* xpoints, const double* ypoints, unsigned npoints) const;
};

#endif /* LAGRANGEINTERPOLATOR_H_ */
